package com.woniu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woniu.dao.HouseMapper;
import com.woniu.dao.RooMapper;
import com.woniu.dao.UserMapper;
import com.woniu.pojo.House;
import com.woniu.pojo.Roo;
import com.woniu.pojo.User;
import com.woniu.service.UserService;
@Service
@Transactional
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private RooMapper rooMapper;
	@Autowired
	private HouseMapper houseMapper;
	@Override
	public List<User> selectUserByHouseId(String house_id) {
		// TODO Auto-generated method stub
		List<User> userList= userMapper.selectUserByHouseId(house_id);
		return userList;
	}
	@Override
	public void updateUserShare(String u_id, String user_share,String h_years) {
		String[] u_ids = u_id.split(",");
		String[] user_shares = user_share.split(",");
		String[] h_yearss = h_years.split(",");
		// TODO Auto-generated method stub
		House house= houseMapper.selectHouseByUserId(u_ids[0]);
		System.out.println(house);
		if(rooMapper.selectRooByHouseId(String.valueOf(house.getH_id()))==null) {
			Roo roo=new Roo();
			roo.setH_years(Integer.valueOf(h_yearss[0]));
			roo.setH_id(house.getH_id());
			String roo_id="A";
			roo.setRoo_id(roo_id+house.getHouse_id());
			rooMapper.addROO(roo);
			houseMapper.updateHouseJurisdictionType("所有权", roo.getRoo_id(),String.valueOf(house.getH_id()));
		}else {
			rooMapper.updateROO(h_yearss[0], house.getHouse_jurisdictionNumber());
		}
		for(int i=0;i<u_ids.length;i++) {
			userMapper.updateUserShare(u_ids[i], user_shares[i]);
		}
	}

}
